package com.jin.webvideo.websocket.shareroom;

import com.jin.webvideo.util.sys.EncryptUtil;
import org.springframework.web.socket.WebSocketSession;

import java.util.HashMap;
import java.util.Map;

public class ShareRoom {
    public static final int STATUS_NEW = 0;
    public static final int STATUS_OPEN = 1;
    public static final int STATUS_CLOSE = 2;
    private String roomOwner;
    private long roomId;
    private long createTime;
    private int status;
    private long lastUpdate;
    private ShareVideoInfo videoInfo;

    private Map<String, WebSocketSession> member = new HashMap<>();

    public ShareRoom(long roomId, String owner){
        this.roomId = roomId;
        this.roomOwner = owner;
        this.status = STATUS_NEW;
        videoInfo = new ShareVideoInfo();
        lastUpdate = EncryptUtil.timestamp();
        createTime = lastUpdate;
    }

    public int getStatus() {
        return status;
    }

    public long getRoomId() {
        return roomId;
    }

    public long getLastUpdate() {
        return lastUpdate;
    }

    public ShareVideoInfo getVideoInfo() {
        return videoInfo;
    }

    public String getRoomOwner() {
        return roomOwner;
    }

    public long getCreateTime() {
        return createTime;
    }

    public Map<String, WebSocketSession> getMember() {
        return member;
    }

    public void putMember(String account, WebSocketSession session) {
        member.put(account, session);
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public WebSocketSession remove(String account){
        return member.remove(account);
    }

    public boolean isOpen(){
        return this.status == STATUS_OPEN;
    }
    public boolean isClose(){
        return this.status == STATUS_CLOSE;
    }
}
